package com.ruoyi.course.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.domain.CourseParent;
import com.ruoyi.course.domain.CourseStu;
import com.ruoyi.course.service.ICourseParentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 家长管理Controller
 * 
 * @author ruoyi
 * @date 2025-06-12
 */
@RestController
@RequestMapping("/course/courseParent")
public class CourseParentController extends BaseController
{
    @Autowired
    private ICourseParentService courseParentService;

    /**
     * 查询家长管理列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseParent:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseParent courseParent)
    {
        startPage();
        List<CourseParent> list = courseParentService.selectCourseParentList(courseParent);
        //查询所有家长下方的所有学生
        return getDataTable(list);
    }

    /**
     * 导出家长管理列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseParent:export')")
    @Log(title = "家长管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseParent courseParent)
    {
        List<CourseParent> list = courseParentService.selectCourseParentList(courseParent);
        ExcelUtil<CourseParent> util = new ExcelUtil<CourseParent>(CourseParent.class);
        util.exportExcel(response, list, "家长管理数据");
    }

    /**
     * 获取家长管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseParent:query')")
    @GetMapping(value = "/{parentId}")
    public AjaxResult getInfo(@PathVariable("parentId") Integer parentId)
    {
        return success(courseParentService.selectCourseParentByParentId(parentId));
    }

    /**
     * 新增家长管理
     */
    @PreAuthorize("@ss.hasPermi('course:courseParent:add')")
    @Log(title = "家长管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseParent courseParent)
    {
        return toAjax(courseParentService.insertCourseParent(courseParent));
    }

    /**
     * 修改家长管理
     */
    @PreAuthorize("@ss.hasPermi('course:courseParent:edit')")
    @Log(title = "家长管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseParent courseParent)
    {
        return toAjax(courseParentService.updateCourseParent(courseParent));
    }

    /**
     * 删除家长管理
     */
    @PreAuthorize("@ss.hasPermi('course:courseParent:remove')")
    @Log(title = "家长管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{parentIds}")
    public AjaxResult remove(@PathVariable Integer[] parentIds)
    {
        return toAjax(courseParentService.deleteCourseParentByParentIds(parentIds));
    }

    /**
     * 获取当前家长所在校区所有孩子列表parentId为空
     */
    @GetMapping("getStuByCampusId/{campusId}")
    public AjaxResult getStuByCampusId(@PathVariable("campusId") Integer campusId)
    {
        List<CourseStu> courseStus = courseParentService.getStuByCampusId(campusId);
        AjaxResult ajaxResult = new AjaxResult();

        return ajaxResult.put("courseStus",courseStus);
    }

}
